<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
               "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
lang="utf-8" xml:lang="utf-8">
<head>
<title>Lab2:  Lexer</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2010-04-16 16:25:08 "/>
<meta name="author" content="Zhuang Zhong"/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<link rel="stylesheet" href="style/base.css"  type="text/css" />
<script type="text/javascript">
<!--/*--><![CDATA[/*><!--*/
 function CodeHighlightOn(elem, id)
 {
   var target = document.getElementById(id);
   if(null != target) {
     elem.cacheClassElem = elem.className;
     elem.cacheClassTarget = target.className;
     target.className = "code-highlighted";
     elem.className   = "code-highlighted";
   }
 }
 function CodeHighlightOff(elem, id)
 {
   var target = document.getElementById(id);
   if(elem.cacheClassElem)
     elem.className = elem.cacheClassElem;
   if(elem.cacheClassTarget)
     target.className = elem.cacheClassTarget;
 }
/*]]>*///-->
</script>
</head>
<body>
<div id="content">

<h1 class="title">Lab2:  Lexer</h1>


<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Introduction </h2>
<div class="outline-text-2" id="text-1">

<p>This assignment requires you to write a lexical analyzer of <a href="spec.html"><b>C programming language</b></a>.
</p>
</div>

</div>

<div id="outline-container-2" class="outline-2">
<h2 id="sec-2">Requirement </h2>
<div class="outline-text-2" id="text-2">

<p>You should <a href="lab2-0422.zip"><b>download</b></a> this package and finish "c.lex" "tokens.sml". We have provided a test case "test.c"
</p>

</div>

<div id="outline-container-2.1" class="outline-3">
<h3 id="sec-2.1">Input </h3>
<div class="outline-text-3" id="text-2.1">

<p>Your input files are plain C programs like "test.c".
</p>
</div>

</div>

<div id="outline-container-2.2" class="outline-3">
<h3 id="sec-2.2">Output </h3>
<div class="outline-text-3" id="text-2.2">

<p>The output should be line by line as this form:
</p>


<pre class="example">token AT POS: position
</pre>



<p>
<b>position</b> is the start position of the token in input file and 
starts from <b>0</b>.
</p>
<p>
Output format of <b>token</b>:
</p><dl>
<dt>symbols</dt><dd>
+ - * / ( ) [ ] { } ; &gt; &lt; &gt;= &lt;= == != -&gt; .
</dd>
<dt>keywords</dt><dd>
int char void struct while for if else return 
</dd>
<dt>intconst</dt><dd>
INT(intconst) e.g. 1 =&gt; INT(1)
</dd>
<dt>stringconst</dt><dd>
STRING(stringconst) e.g. "haha" =&gt; STRING("haha")
</dd>
<dt>identifier</dt><dd>
ID(identifier) e.g. main =&gt; ID(main)
</dd>
</dl>


<p>
For example, the output of "test.c" should be:
</p>


<pre class="example">int AT POS:9
ID(main) AT POS:13
( AT POS:17
) AT POS:18
{ AT POS:20
int AT POS:24
ID(a) AT POS:28
= AT POS:29
INT(1) AT POS:30
; AT POS:31
while AT POS:35
( AT POS:40
ID(a) AT POS:41
&gt; AT POS:42
INT(1) AT POS:43
) AT POS:44
{ AT POS:50
ID(a) AT POS:58
= AT POS:59
ID(a) AT POS:60
+ AT POS:61
INT(1) AT POS:62
; AT POS:63
} AT POS:69
return AT POS:73
ID(a) AT POS:80
; AT POS:81
} AT POS:83
</pre>




</div>
</div>

</div>

<div id="outline-container-3" class="outline-2">
<h2 id="sec-3">Hints </h2>
<div class="outline-text-2" id="text-3">

<ol>
<li>
<a href="http://www.smlnj.org/doc/ML-Lex/manual.html">ML-lex manual</a>
</li>
<li>
See <a href="spec.html">Specification</a> of our C language
</li>
<li>
Finish datatype <b>token</b> and function <b>toString</b> in "tokens.sml"
</li>
<li>
Finish the rules in "c.lex"
</li>
<li>
Before compile , you need to <b>manually run</b> "&lt;path to your mlton bin&gt;/mllex &lt;your lex file&gt;".
Notice that we use mllex of <b>MLton</b> not SML/NJ
</li>
</ol>









</div>
</div>
<div id="postamble">
</div>
</div>
</body>
</html>
